<!DOCTYPE html>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<html class="win-frame">
<head>
<title>${name_china}管理-新建${name_china}</title>
 <%@include file="/common/head.jsp" %>

</head>
<body class="iframe-page">
<div class="page-title-wrapper">
    <div class="page-title">
        <div class="page-title-text">
            <span>${name_china}管理</span>
            <span class="split"></span>
            <span>新建${name_china}</span>
        </div>
        <a id="goBack" class="btn-return distance-left" href="javascript:;"><i class="icon icon-arrow-left"></i>返回上级</a>
    </div>
    <div class="page-title-border"></div>
</div>

<form id="addForm" method="post">
  <div id="left" style="width:80%;float:left">
	 <div class="form-wrapper">
		<div class="h4 distance-double">
	        <span class="h4-title"><i class="icon icon-setting"></i>基本信息</span>
	        <span class="h4-border"></span>
	    </div>
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>配置类型</p>
	        <input type="text" id="rateType" name="rateType" class="summer-input summer-validatebox" /> 
	     </div>
	     
	     <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>最低条件</p>
	        <input type="text" id="minCondition" name="minCondition" class="summer-input summer-validatebox" disabled/> 
	     </div> 
	     
	      <div class="form-cont">
	        <p class="form-cont-title"><span class="field-required">*</span>最高百分比</p>
	        <input type="text" id="maxCondition" name="maxCondition" class="summer-input summer-validatebox" /> 
	     </div> 
	     
	      <div class="form-cont">
	        <p class="form-cont-title">分数</p>
	        <input type="text" id="marks" name="marks" class="summer-input summer-validatebox"  data-validatebox="validType:['required','maxLength[500]']"/> 
	     </div>
	     
	    <div class="form-cont">
	        <p class="form-cont-title">备注</p>
	        <textarea class="summer-textarea" id="note" name="note"></textarea>
	     </div>
	 <div class="form-btn-wrapper" id="funcbar">
        <a class="btn btn-normal" id="backBtn">关闭</a>
    </div>
  </div>
  </div>
	
</form>
<script>
    var  permission = CommonUtil.getPermission('${name_english}');
    $(function () {
    	//初始化funcbar
     	$('#funcbar').prepend($.funcbar({
            type: 'button',
            data: permission,
            permit: ['${name_english}:add']
        }));
     	//初始化下拉选项
   	 	//初始化下拉选项
		$('#rateType').combobox({
			valueField : 'code',
			textField : 'name',
			url : COMMON_URL.getCode + '?type=T_DM_T_PROJECT_LIVING_RATE_TYPE'
		});
     	//选中类型时查找该类型下最大条件作为新增的最小条件
		$('#rateType').combobox({
			onSelect: function (record) {
				console.log(record.code);
					$.ajax({
						   url: CONST_URL.GET_MINCOND,//请求的后台地址
						   data:{
								"rateType":trimSpace(record.code)
							},//前台传给后台的参数
						   success: function(data){//msg:返回值
						     console.log(data);
							$("#minCondition").val(data.minCond);
						   }
						});
		        }
		    });

    	//保存按钮
    	$('#funcbar').on('click', 'a[data-permit="${name_english}:add"]', {isContinue: false},  submit);
    	
    	//返回按钮
    	$('#backBtn,#goBack').on('click',backMain);
    	
    });
    
    
    //表单提交
    function submit(event) {
        var minp = $("#minCondition").val().split("."); 
        var maxp = $("#maxCondition").val().split(".");
        var isCorrect = "true";
        if(minp.length == 2){
        	if(minp[1].length >2){
        		isCorrect = "false";
        		alert("最小条件数小数点最多两位！");
        	}
        }
        if(maxp.length == 2){
        	if(maxp[1].length>2){
        		isCorrect = "false";
        		alert("最大条件数小数点最多两位！");
        	}
        }
        if(isCorrect == "true"){
        	$("#addForm").form({
           	 buttons : ['#saveBtn','#saveBtnContinue'],
                ajax: {
                    url: CONST_URL.ADD
                },
                onSubmitSuccess: function (data) {
               		console.log(data);
                	if(data.msg != "null"){
               			alert(data.msg);
               		}else{
               			$.stip({
         	                type:'ok',//显示类型 有info、 ok、 danger
         	                text: '保存成功！',
         	                onBeforeHide: function () {
         	            	  var isContinue = event.data.isContinue;
                          	  if (isContinue) {
                                 resetForm();
                          	  } else {
                          		  backMain();
                          	  }
         	               }
                     	});
               		}
                 }
            }).form("submit");
        }
    }
    
    //保存并继续清空form
    function resetForm(){
        //$('#xm,#zw,#cs,#bgdh,#sjhm').val('');
    }
    
    //返回主页面
    function backMain() {
    	window.location.href = CONST_URL.INIT_MAIN;
    }
    
   
    //请求url
    var CONST_URL = {
    	INIT_MAIN: basePath + "${common_url}init",
       	ADD: basePath + "${common_url}add",
       	GET_MINCOND: basePath + "${common_url}getMincond"
    };
    
</script>
</body>
</html>